package org.iwidget.desktop.core.javascript;

/**
 *
 * @author Muhammad Hakim A
 */
import org.iwidget.desktop.core.Iwidget;
import org.iwidget.desktop.model.WidgetElement;
import org.mozilla.javascript.*;

public class IwidgetMouse extends ScriptableObject
{

    public String getClassName()
    {
        return "mouse";
    }

    public IwidgetMouse()
    {
    }

    public void jsConstructor()
    {
    }

    public void jsSet_screenX(int i)
    {
    }

    public int jsGet_screenX()
    {
        return Iwidget.iwidgetMouse.mouseX;
    }

    public void jsSet_screenY(int i)
    {
    }

    public synchronized int jsGet_screenY()
    {
        return Iwidget.iwidgetMouse.mouseY;
    }

    public void jsSet_x(int i)
    {
    }

    public int jsGet_x()
    {
        try{
            WidgetElement widget;
            Object obj;
            widget = null;
            Scriptable scope = ScriptableObject.getTopLevelScope(getParentScope());
            obj = scope.get("widget", scope);
            Object obj2 = Context.toType(obj, org.iwidget.desktop.model.WidgetElement.class);
            if(obj2 != null)
                widget = (WidgetElement)obj2;
            return Iwidget.iwidgetMouse.mouseX - widget.getUIComponent().getX();
        }catch(Exception e){
            return 0;
        }
    }

    public void jsSet_y(int i)
    {
    }

    public int jsGet_y()
    {
        try{
            WidgetElement widget;
            Object obj;
            widget = null;
            Scriptable scope = ScriptableObject.getTopLevelScope(getParentScope());
            obj = scope.get("widget", scope);
            Object obj2 = Context.toType(obj, org.iwidget.desktop.model.WidgetElement.class);
            if(obj2 != null)
                widget = (WidgetElement)obj2;

            return Iwidget.iwidgetMouse.mouseY - widget.getUIComponent().getY();
        }catch(Exception e){
            return 0;
        }
    }

    private static final long serialVersionUID = 0x2d34333330353335L;
}